#ifndef IMAGEPROVIDER_H
#define IMAGEPROVIDER_H

#include "source/imagerecord.h"
#include <QQuickImageProvider>
#include <QImage>
#include <opencv2/core/mat.hpp>

class ImageProvider : public QObject, public QQuickImageProvider {
    Q_OBJECT
    Q_PROPERTY(QList<qint16> imageMainInfo READ imageMainInfo NOTIFY imageMainInfoChanged)

public:
    enum ImageDisplay {
        Capture,
        Reprogress,
        defaultImg,
    };

    static ImageProvider &getInstance();


    QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
    void image2qml(const cv::Mat& image, const QString &target,
                   const ImageDisplay step = defaultImg);

    QList<qint16> imageMainInfo() const {return m_imagemainInfo ; };
    cv::Mat getMainImg() const {return m_mainImage;};
    void getMainDisplay(cv::Mat &img ,  ImageDisplay &step);

signals:
    void box1ImageReady(const QUrl &imageUrl);
    void box2ImageReady(const QUrl &imageUrl);
    void mainImageReady(const QUrl &imageUrl);

    void popImageReady(const QUrl &imageUrl);
    void pop2ImageReady(const QUrl &imageUrl);

    void popEyeImageReady(const QUrl &imageUrl);

    void imageMainInfoChanged();

private:
    ImageProvider(QObject *parent = nullptr);
    ImageProvider& operator=(const ImageProvider& rhs) = delete;

    QList<qint16> m_imagemainInfo;

    cv::Mat m_mainImage;
    ImageDisplay m_mainStep;

    QImage box1Image;
    QImage box2Image;
    QImage popImage;
    QImage pop2Image;
    QImage pop2EyeImage;
    QImage mainImage;
    QImage convertToQImage(const cv::Mat &mat);
    int imageCounter;

};

#endif // IMAGEPROVIDER_H
